import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
import store from './store/index'
import mandMobile from 'mand-mobile'
import * as FastClick from 'fastclick'
import 'lib-flexible/flexible'
import 'mand-mobile/lib/mand-mobile.css'
import Viser from 'viser-vue'
// import VueWechatTitle from 'vue-wechat-title'

const setWechatTitle = (title: any, img: any) => {
    if (title === undefined || window.document.title === title) {
        return
    }
    document.title = title
    const mobile = navigator.userAgent.toLowerCase()
    if (/iphone|ipad|ipod/.test(mobile)) {
        const iframe = document.createElement('iframe')
        iframe.style.display = 'none'
        // 替换成站标favicon路径或者任意存在的较小的图片即可
        iframe.setAttribute('src', img || '')
        const iframeCallback = () => {
            setTimeout(() => {
                iframe.removeEventListener('load', iframeCallback)
                document.body.removeChild(iframe)
            }, 0)
        }
        iframe.addEventListener('load', iframeCallback)
        document.body.appendChild(iframe)
    }
}
Vue.directive('wechat-title', (el: any, binding: any) => {
    setWechatTitle(binding.value, el.getAttribute('img-set') || null)
})


Vue.use(Viser)
// Vue.use(VueWechatTitle)

FastClick.attach(document.body)
Vue.use(mandMobile)

Vue.config.productionTip = false

import '@/directive'
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
